grammar S;

options {
    language=Java;
    output=AST;
    ASTLabelType=CommonTree; // type of $stat.tree ref etc...
}

tokens {
	SCHEMA;
	TABLE;	
	COLUMN;	
	PROPERTY;
}

@lexer::header {
/**
 * Database sync lexor
 * 
 * @author dzhang
 */
package org.niko.ds.parser;
}

@header {
/**
 * Database sync parser
 * 
 * @author dzhang
 */
package org.niko.ds.parser;
}

prog	:	schema;

schema	:	'schema' ID ':'  table+		->^(SCHEMA ID table+ );

table	:	'table' ID ':'  'columns:' column+ ->^(TABLE ID column+);

column	:	ID ':'  col='{' meta+ '}'	-> ^(COLUMN[$col,"COLUMN"] ID meta+ );

meta	:	info (',' info)*;

info	:	'type'  TYPE			->^(PROPERTY 'type' TYPE)			
		|'size'  INT			->^(PROPERTY 'size' INT)
		|'notnull'  BOOLEAN_LITERAL	->^(PROPERTY 'notnull' BOOLEAN_LITERAL)	
		|'pk'  BOOLEAN_LITERAL	->^(PROPERTY 'pk' BOOLEAN_LITERAL);
		
// p	:	'type' | 'size' | 'notnull' | 'pk';

TYPE	:	'bigint' | 'varchar' | 'int' | 'double' | 'BIGINT' | 'VARCHAR' | 'INT' | 'DOUBLE';

BOOLEAN_LITERAL	:	'TRUE' | 'FALSE' | 'true' | 'false';

ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;

INT :	'0'..'9'+
    ;

WS:		(' ' |'\t' |'\n' |'\r' )+ {skip();} ;